import { useCallback, useEffect, useState } from 'react';
import useBasisCash from './useBasisCash';
import { TokenStat } from '../basis-cash/types';
import config from '../config';
import { openGroup } from '../views/Banks/Banks';

const useLiquidityOracleTVLine = (group: string) => {
  const [stat, setStat] = useState(false);
  const basisCash = useBasisCash();

  const fetchLiquidityOracleTVLine = useCallback(async () => {
    if (config.plane[config.group].lpOracle != null) {
      const enable = await basisCash.getLiquidityOracleTVLine(group);
      setStat(enable);
    }
    
  }, [basisCash, config.group]);

  useEffect(() => {
    fetchLiquidityOracleTVLine().catch((err) => console.error(`Failed to fetch SNB price: useCashStats ${err.stack}`));
    const refreshInterval = setInterval(fetchLiquidityOracleTVLine, config.refreshInterval);
    return () => clearInterval(refreshInterval);
  }, [basisCash, config.group]);

  return stat;
};

export default useLiquidityOracleTVLine;
